/*
 * motion_state.cpp
 *
 *  Created on: 31.03.2011
 *      Author: inkooboo
 */

#include "motion_state.hpp"

motion_state_t::motion_state_t(const world_transform_t &init_pos, boost::shared_ptr<scene_node_t> &scene_node) :
    position_(init_pos), scene_node_(scene_node)
{
    scene_node_->update_world_transform(init_pos);
}

motion_state_t::~motion_state_t()
{
}


void motion_state_t::getWorldTransform(btTransform &worldTrans) const
{
    btVector3 pos(position_.position.x, position_.position.y, position_.position.z);
    worldTrans.setOrigin(pos);
    btQuaternion rot(position_.rotation.x, position_.rotation.y, position_.rotation.z, position_.rotation.w);
    worldTrans.setRotation(rot);
}

void motion_state_t::setWorldTransform(const btTransform &worldTrans)
{
    world_transform_t tmp;
    btQuaternion rot = worldTrans.getRotation();
    tmp.rotation = quaternion_t(rot.w(), rot.x(), rot.y(), rot.z());
    btVector3 pos = worldTrans.getOrigin();
    tmp.position = vector3_t(pos.x(), pos.y(), pos.z());
    scene_node_->update_world_transform(tmp);
}

void motion_state_t::setKinematicPos(const btTransform &currentPos)
{
    setWorldTransform(currentPos);
}
